/**
 * Created on 20/04/2008
 * 
 */
package com.apbetioli.mapr.place.dao;

import com.apbetioli.mapr.place.entity.Place;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityTransaction;

/**
 *
 * @author Alexandre Parra Betioli
 */
public final class PlacesDao extends PlacesDaoNoTransaction {

    @Override
    public Place save( final Place place ) {
        EntityTransaction et = super.getTransaction();
        Place old = null;

        try {
            et.begin();
            old = super.save(place);
            et.commit();
        } catch (RuntimeException e) {
            Logger.getLogger(PlacesDao.class.getName()).log(Level.SEVERE, null, e);
            if (et.isActive()) {
                et.rollback();
            }
            throw e;
        }

        return old;
    }

    @Override
    public Place delete( final String name ) {
        EntityTransaction et = super.getTransaction();
        Place old = null;
        try {
            et.begin();
            old = super.delete(name);
            et.commit();
        } catch (RuntimeException e) {
            Logger.getLogger(PlacesDao.class.getName()).log(Level.SEVERE, null, e);
            if (et.isActive()) {
                et.rollback();
            }
            throw e;
        }

        return old;
    }
}
